<template>
	<view>
		<scroll-view scroll-x="true" class="arts">
			<view class="tip">
				<view class="tipItem" :class="tipIndex == index ? 'tipActive':''" v-for="(item,index) in tipList" :key="index" @tap="tipClick(index)">{{item.title}}</view>
			</view>
		</scroll-view>
		<list :list='news' :status="status" :contentText="contentText" stateType="2" addType="2"></list>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	import list from '@/components/artlist/artlist';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default{
		components: {
			list,
			uniLoadMore
		},
		data() {
			return {
				page: 1,
				reload: true,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				news: [], //文章列表
				tipList: [
					{is_show:0,title:'没审核'},
					{is_show:1,title:'已通过'},
					{is_show:2,title:'已拒绝'}
				], //标签列表
				tipIndex: 0, //标签索引
			}
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.getArt();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getArt();
			}, 500);
		},
		onShow() {
			this.reload = true;
			this.page = 1;
			this.getArt()
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: 'article-release?stateType=2&addType=2'
			})
		},
		methods: {
			/* 获取文章列表 */
			getArt() {
				var data = {
					page: this.page,
					pagesize: 7,
					is_show: this.tipList[this.tipIndex].is_show || 0
				}
				this.$zapi.apiPost('user/information.Lists/InformationList', data).then(res => {
					if (res.data.code == 200 && res.data.data.data) {
						var list = res.data.data.data;
						for (var i = 0; i < list.length; i++) {
							list[i].time = util.getBriefTime(list[i].creat_time);
						}
						this.news = this.reload ? list : this.news.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.news = [];
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			/* tip切换 */
			tipClick(index) {
				this.tipIndex = index;
				this.reload = true;
				this.page = 1;
				this.getArt()
			}
		},
	}
</script>

<style>
	/* 内容 */
	.arts{
		position: fixed;
		top: 0upx;
		left: 0;
		background: #FAFAFA;
	}
	.tip{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		border-top: 30upx solid #FAFAFA;
		border-bottom: 30upx solid #FAFAFA;
		white-space: nowrap;
	}
	.tipItem{
		color: #999999;
		font-size: 30upx;
		padding: 8upx 22upx;
		border: 2upx solid #CCCCCC;
		line-height: 1;
		text-align: center;
		border-radius: 26upx;
		margin-left: 30upx;
		margin-right: 10upx;
	}
	.tipActive{
		color: #FFFFFF;
		background: #FF9900;
		border: 2upx solid #FF9900;
	}
</style>